package com.demo.bookstore.dao.impl;

import com.demo.bookstore.bean.User;
import com.demo.bookstore.dao.UserDao;

/**
 * @author ddone
 * @date 2024/3/12-12:16
 */
public class UserDaoImpl extends BaseDaoImpl implements UserDao {
    @Override
    public User findUserByUp(User user) {
        String sql = "SELECT userid, username, pwd, email FROM user where username=? and pwd=?";
        return this.getBean(User.class,sql,user.getUsername(),user.getPwd());
    }

    @Override
    public int insertUser(User user) {
        String sql = "INSERT INTO user(username, pwd, email) VALUES(?,?,?)";
        return this.update(sql, user.getUsername(), user.getPwd(), user.getEmail());
    }

    @Override
    public int checkUserName(String username) {
        String sql = "select count(1) from user where username=?";
        return Integer.parseInt(this.getValue(sql,username).toString());
    }
}
